﻿<?php 
	if($row['commentAllowed'])
	{
		if(isset($_SESSION["user_id"]))
		{ 
			if($user['statusID'] != 11 && $user['statusID'] != 13 ) {?>
			<div class="list-comm clearfix">
				<h4>Ecrire un commentaire</h4>
				<form method = "post" action = "article.php?id=<?= $_GET['id'] ?>" enctype="multipart/form-data" class="form-horizontal">
					<textarea class="form-control col-xs-12 wrCom" rows="5" cols="80" name = "wrCom" maxlength="500" ></textarea>
					<span class="col-xs-9"></span>
					<button type = "submit" name = "subCom" class="btn btn-primary btn-lg col-xs-3">Publier</button>
				</form>
			</div>
			<br />
<?php		}
			else
			{	?>
			<div class="alert alert-danger center-block text-center half-size">
				Vous n'avez pas le droit d'écrire un commentaire.
			</div>
			
<?php		}
		}
		else
		{?>
			<div class="alert alert-danger center-block text-center half-size">
				Vous devez vous <a href = "../connexion.php?redirect=true">connecter</a>, ou vous <a href = "../inscription.php" >inscrire</a> pour écrire un commentaire.
			</div>
<?php	}
		if(isset($res_comms))
		{
			while($row_comms = mysqli_fetch_array($res_comms))
			{ ?>
				<div class="list-comm clearfix">
					<div class="pull-left">
						<?php if(isset($row_comms['link']) && $row_comms['imgStatus'] != 3) { ?>
								<img src="<?= imgLink($row_comms['link']) ?>" class="img-rounded" height="102px" width="102px" />
						<?php } else { ?>
								<img src="<?= imgLink("img/avatar/default.png") ?>" class="img-rounded" height="102px" width="102px" />
						<?php }?>
					</div>
					<div class="comm pull-left">
						<div class="info-comm clearfix">
							<span class="pull-left">Par <a href="<?= WEBROOT ?>user/user.php?id=<?= $row_comms['autorID'] ?>"><?= $row_comms["autor"] ?></a></span>
							<span class="pull-right"><?= strftime("le %d %B %Y à %H:%M:%S",strtotime($row_comms['date'])); ?></span>
						</div>
						<div id = "content<?= $row_comms['id'] ?>">
							<?= $row_comms["content"] ?>
							<br/>
<?php 					if(isset($_SESSION["user_id"]))
						{
							if($row_comms['autorID'] == $_SESSION['user_id'] || $user['roleID'] >= 2)
							{ ?>
								<br />
								<a href= "#commentEdit" class="btn btn-sm btn-primary inline-form" onclick = "replace('commentEdit<?= $row_comms['id'] ?>','content<?= $row_comms['id'] ?>', 'content<?= $row_comms['id'] ?>')">Editer</a>
								<form action="article.php?id=<?= $_GET['id'] ?>" method="post" class="inline-form">
									<input type = "hidden" name = "id" value = "<?= $row_comms['id'] ?>"></input>
									<button type = "submit" name = "deleteCom" class = "btn btn-sm btn-danger inline-form" >Supprimer</button>
								</form>
<?php 						}
						} ?>
						</div>
<?php 					if(isset($_SESSION["user_id"]))
						{
							if($row_comms['autorID'] == $_SESSION['user_id'] || $user['roleID'] >= 2)
							{ ?>
								<div id = "commentEdit<?= $row_comms['id'] ?>" style = "display: none;">
									<form method = "post" action = "article.php?id=<?= $_GET['id'] ?>" class="form-horizontal">
										<input type = "hidden" name = "id" value = "<?= $row_comms['id'] ?>"></input>
										<textarea class="col-xs-12 form-control" rows="5" cols="80" name = "wrCom" ><?= $row_comms["content"]?></textarea>
										<span class="col-xs-9"></span>
										<button type = "submit" name = "editCom" class = "btn btn-primary col-xs-3" >Editer</button>
									</form>
								</div>
<?php						}
						} ?>
					</div>
					<div class="comm-note pull-right">
						<div class="pull-left">
							<div class="note pull-right">
								<?= colorNote($row_comms['note']) ?>
							</div>
						</div>
						<div class="pull-right">
							<form action="article.php?id=<?= $_GET['id'] ?>" method="post">
								<input type="hidden" name="comID" value ="<?= $row_comms['id'] ?>" />
								<input type="hidden" name="comType" value="1"/>
								<button class="note-pouce" type="submit" name="note" value="1">
								<span class="<?php if($row_comms['pouce'] == 1) { echo 'note-green '; } ?>
								glyphicon glyphicon-thumbs-up" aria-hidden="true"></span>
								</button>
								<button class="note-pouce" type="submit" name="note" value="-1">
									<span class="<?php if($row_comms['pouce'] == -1) { echo 'note-red '; } ?>
									glyphicon glyphicon-thumbs-down" aria-hidden="true"></span>
								</button>
							</form>
						</div>
					</div>
				</div>
<?php		}
		} 
	}
	else
	{?>
		<div class="alert alert-danger center-block text-center half-size">
			Les commentaires ont été désactivés pour cet article.
		</div>
	<?php
	} ?>